package com.smartmedi.ai.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartmedi.ai.domain.dto.JhInMrRequsetPage;
import com.smartmedi.ai.domain.entity.JhInMr;
import com.smartmedi.ai.service.JhInMrService;
import com.smartmedi.ai.mapper.JhInMrMapper;
import org.springframework.stereotype.Service;

/**
* @author XWQ
* @description 针对表【JH_IN_MR(住院电子病历记录（病历索引和大文本编码）)】的数据库操作Service实现
* @createDate 2025-07-17 13:08:31
*/
@Service
public class JhInMrServiceImpl extends ServiceImpl<JhInMrMapper, JhInMr>
    implements JhInMrService{

    /**
     * 获取查询条件
     * @param jhInMrRequsetPage 查询参数
     * @return 查询条件
     */
    @Override
    public QueryWrapper<JhInMr> getQueryWrapper(JhInMrRequsetPage jhInMrRequsetPage) {
        QueryWrapper<JhInMr> queryWrapper = new QueryWrapper<>();
        if (jhInMrRequsetPage == null) {
            return queryWrapper;
        }

        String inMrSn = jhInMrRequsetPage.getInMrSn();
        String inHospSn = jhInMrRequsetPage.getInHospSn();
        String mrCode = jhInMrRequsetPage.getMrCode();
        String createTime = jhInMrRequsetPage.getCreateTime();
        String fileFlag = jhInMrRequsetPage.getFileFlag();
        String patientSn = jhInMrRequsetPage.getPatientSn();

        String sortField = jhInMrRequsetPage.getSortField();
        String sortOrder = jhInMrRequsetPage.getSortOrder();

        queryWrapper.eq(StringUtils.isNotBlank(fileFlag), "FILE_FLAG", fileFlag);
        queryWrapper.eq(StringUtils.isNotBlank(patientSn), "PATIENT_SN", patientSn);
        queryWrapper.eq(StringUtils.isNotBlank(inMrSn), "IN_MR_SN", inMrSn);
        queryWrapper.eq(StringUtils.isNotBlank(inHospSn), "IN_HOSP_SN", inHospSn);
        queryWrapper.eq(StringUtils.isNotBlank(mrCode), "MR_CODE", mrCode);
        queryWrapper.eq(StringUtils.isNotBlank(createTime), "CREATED_T", createTime);

        // 排序
        queryWrapper.orderBy(StrUtil.isNotEmpty(sortField), sortOrder.equals("MR_CODE"), sortField);
        return queryWrapper;
    }

    @Override
    public Long addJhInMr(JhInMr jhInMr) {
        //返回一个假的值
        return 1L;
    }
}




